﻿Public Module Extensions
    <System.Runtime.CompilerServices.Extension()>
    Public Function ToHTML(ByVal color As System.Drawing.Color) As String
        Return (color.ToArgb And (2 ^ 24 - 1)).ToString("X6")
    End Function

    <System.Runtime.CompilerServices.Extension()>
    Public Function ToColor(ByVal html As String) As System.Drawing.Color
        If System.Text.RegularExpressions.Regex.IsMatch(html, "^[\da-f]{6}$") Then
            html = "#" & html
        End If

        Return System.Drawing.ColorTranslator.FromHtml(html)
    End Function
End Module